#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int x=0;bool f=0;char ch=getchar();
	while(ch<'0'||ch>'9')f^=(ch=='-'),ch=getchar();
	while('0'<=ch&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int Maxn=2e5+5;
int k,m;
char s[Maxn];
char a[Maxn];
int q;
struct node{int l,r,x;}b[Maxn];
namespace sub1{
	inline void solve(){
		int n=strlen(s+1);
		for(int i=1;i<=q;i++){
			for(int j=1;j<=n;j++)a[j]=s[j];
			int len=b[i].x;
			for(int j=b[i].l;j<=b[i].r;j++){
				if(len==m)break;
				a[++len]=s[j];
			}
			for(int j=b[i].x+1;j<=n;j++){
				if(len==m)break;
				a[++len]=s[j];
			}
			n=len;
			for(int j=1;j<=n;j++)s[j]=a[j];
		}
		for(int i=1;i<=k;i++)printf("%c",s[i]);
	}
}
int main(){
	freopen("copy.in","r",stdin);
	freopen("copy.out","w",stdout);
	k=read();m=read();
	scanf("%s",s+1);
	q=read();
	for(int i=1;i<=q;i++)b[i]={read()+1,read(),read()};
	if(max(q,m)<=2000)sub1::solve(),exit(0);
	return 0;
}

